package com.leete;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.FileNotFoundException;
import java.util.Locale;

public class Main implements BeanNameAware, BeanFactoryAware, InitializingBean {



    public static void main(String[] args) throws FileNotFoundException {

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:application.xml");
        AbstractA a = (AbstractA) applicationContext.getBean("a", A.class);
        System.out.println(a.getMessage("name", Locale.CHINESE));
        System.out.println(a.getMessage("name", Locale.ENGLISH));


       /* ResourceLoader resourceLoader = new DefaultResourceLoader();
        Resource resource = resourceLoader.getResource("classpath:application.xml");
        BeanFactory beanFactory = new XmlBeanFactory(resource);
        B b = (B) beanFactory.getBean("b");
        System.out.println(b.getA());
        A a = (A) beanFactory.getBean("a");
        System.out.println(a.getB());*/

    }

    public void setBeanName(String name) {
        System.out.println(name);
    }

    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println(beanFactory);
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println("main对象初始化");
    }
}
